/**
 *  *2010-6-2 下午10:45:35  add 
 */
package com.base.myproject.client.HR.bcode;

import java.util.ArrayList;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.BO.BusiObject;
import com.base.myproject.client.jdbc.DataSet;
import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.tools.CommandSyncContainer;
import com.base.myproject.client.tools.CommandSyncExeSql;
import com.base.myproject.client.tools.CommandSyncGetModelDatas;
import com.base.myproject.client.tools.CommandSyncReturnObject;
import com.base.myproject.client.tools.CommandSyncsql;
import com.base.myproject.client.tools.GreetingService;
import com.base.myproject.client.tools.GreetingServiceAsync;
import com.base.myproject.client.ui.BaseFormPanel;
import com.base.myproject.client.ui.BaseJDBCPanel;
import com.base.myproject.client.ui.celleditor.BaseComboBoxForm;
import com.base.myproject.client.ui.celleditor.BaseComboBoxX;
import com.base.myproject.client.ui.dialog.SelectItemDialog;
import com.extjs.gxt.ui.client.GXT;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.Style.VerticalAlignment;
import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.MessageBoxEvent;
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.fx.FxConfig;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
import com.extjs.gxt.ui.client.widget.Info;
import com.extjs.gxt.ui.client.widget.ListView;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.FieldSet;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.layout.TableData;
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.DeferredCommand;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Label;

/**
 * @author Administrator
 *2010-6-2
 * javazgw@gmail.com
 */
public class HR_Wardrode extends BaseJDBCPanel{
	ListView<BusiObject> view = null;
	ListView<BusiObject> bcodeview = null;
	
	TextField<String> seach_code  = new TextField<String>(); 
	TextField<String> seach_text  = new TextField<String>(); //查询框
	Button seach = new Button("衣柜查询");
	
	Button addhoster = new Button("添加衣柜");
	Button delhoster = new Button("删除衣柜");
	Button addbcode = new Button("更改使用人员");
	
	Button show_empty = new Button("空衣柜");
	Button show_break = new Button("已损坏衣柜");
	
	Button btnAddBcode = new Button("添加人员");

	HrBcodeSelectButton hrbsb ;
	Button delbcode = new Button("删除人员");
	
	public HR_Wardrode() {
		super();
		init();
    
	}
	
	public void init() {
		this.add(initWeigetx());
		addhoster.addListener(Events.Select, getListener());
		delhoster.addListener(Events.Select, getListener());
		addbcode.addListener(Events.Select, getListener());
		show_break.addListener(Events.Select, getListener());
		show_empty.addListener(Events.Select, getListener());
		btnAddBcode.addListener(Events.Select, getListener());
		delbcode.addListener(Events.Select, getListener());
		registerMainStore(store);
		registerStore(store);
	}
	
	public ContentPanel initWeigetx() {
		ContentPanel panel = new ContentPanel();
		panel.setHeaderVisible(false);
		panel.setBodyBorder(false);
		HorizontalPanel h1 = new HorizontalPanel();
		HorizontalPanel h = new HorizontalPanel();
		HorizontalPanel h3 = new HorizontalPanel();
		HorizontalPanel h4 = new HorizontalPanel();
		HorizontalPanel h5 = new HorizontalPanel();
		h.setSpacing(3);
		h3.setSpacing(1);
		h4.setSpacing(1);
		h5.setSpacing(1);
		h.add(CreateView()); //显示左边的衣柜列表
		
		h1.add(btnAddBcode);
		h1.add(delbcode);
		btnAddBcode.setWidth(70);
		
		VerticalPanel v2 = new VerticalPanel();
		v2.setSpacing(3);
		HorizontalPanel h2 = new HorizontalPanel();
		h2.add(addhoster);
		h2.add(delhoster);
		
		FieldSet fs = new FieldSet();
		fs.setHeight(85);
		fs.add(h3);
		fs.add(h4);
		fs.add(h5);
		h3.add(new Label("衣柜编号 :"));
		
		h4.add(new Label("衣柜名称 :"));
		h5.add(new Label(" 　　　　　　　　　　　　"));
		h5.add(seach);
		h5.add(show_break);
		h5.add(show_empty);
		h3.add(seach_code);
		h4.add(seach_text);
		v2.add(fs);
		v2.add(CreateBcodeView());
		v2.add(h1);
		v2.add(createForm());
		v2.add(h2);
		seach.addListener(Events.Select, getListener());
		
		h.add(v2);
		panel.add(h);
		return panel;
	}

	BaseStore<BusiObject> store = null;

	BaseStore<BusiObject> getStore() {
		if (store == null) {
			createStore();
		}
		return store;
	}

	BaseStore<BusiObject> createStore() {

		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.setTotalName("totle");
		type.addField("icode");
		type.getField("icode").setType(Long.class);
		type.addField("code");
		type.getField("code").setType(String.class);
		type.addField("name");
		type.getField("name").setType(String.class);
		type.addField("sex");
		type.getField("sex").setType(String.class);
		type.addField("status");
		type.getField("status").setType(String.class);
	
		type.addField("mark");
		type.getField("mark").setType(String.class);
		type.addField("imagepath");
		type.getField("imagepath").setType(String.class);
		type.addField("usedcount");
		type.getField("usedcount").setType(Integer.class);
		StoreInfo info = new StoreInfo();
		info.setTablename("hr_wardrobe");
		info.setKeyname(new String[] { "icode"});
		info.setSql("select icode,code,name,sex,status,mark,'images/b2cimages/wardrode.gif' as imagepath,(select count(*) from hr_wardrode_bcode where hr_wardrobe.code=hr_wardrode_bcode.upcode ) as usedcount  from hr_wardrobe");
		info.setForcenolimit("true");
		// info.setParent(mainstore);// 关联主表
		// info.setLinkparentcolumns(new String[] { "icode" }); // 关联主表字段
		// info.setLinkparent_chile_columns(new String[] { "upicode" });//
		// 关联主表字段
		store = new BaseStore<BusiObject>(type, info);
		return store;
	}
	BaseStore<BusiObject> hr_wardrode_bcodestore = null;
	BaseStore<BusiObject> gethr_hostel_bcodeStore(){
	if(hr_wardrode_bcodestore==null) 
	{
		createhr_wardrode_bcodeStore();
	}
	return hr_wardrode_bcodestore;}
	ModelType type;
	BaseStore<BusiObject> createhr_wardrode_bcodeStore(){
	type = new ModelType();
	type.setRoot("records");
	type.setRecordName("record");
	type.setTotalName("totle");
	type.addField("icode");
	type.getField("icode").setType(Long.class);
	type.addField("upcode");
	type.getField("upcode").setType(String.class);
	type.addField("bcode");
	type.getField("bcode").setType(String.class);
	type.addField("bname");
	type.getField("bname").setType(String.class);
	type.addField("status");
	type.getField("status").setType(String.class);
	type.addField("imagepath");
	
	type.getField("imagepath").setType(String.class);
	type.addField("departments");
	type.getField("departments").setType(String.class);
	StoreInfo info = new StoreInfo();
	info.setTablename("hr_wardrode_bcode");
	info.setKeyname(new String[] { "icode"});

	info.setSql("select icode,upcode,bcode,bname,status,(select top 1 bcodeimagepath from bcode_images where bcode_images.bcode=hr_wardrode_bcode.bcode) as imagepath from hr_wardrode_bcode  where upcode='{code}'");
	info.setParent(store);// 关联主表
	info.setLinkparentcolumns(new String[] { "code" }); // 关联主表字段
	info.setLinkparent_chile_columns(new String[] { "upcode" });// 关联主表字段
	hr_wardrode_bcodestore = new BaseStore<BusiObject>(type, info);
	 return hr_wardrode_bcodestore;}
	
	
	ContentPanel CreateView() {
		final ContentPanel panel = new ContentPanel();
		panel.setHeaderVisible(false);

		panel.setFrame(true);
		panel.setId("images-view");
		panel.setWidth(700);
		panel.setHeight(510);
		panel.setBodyBorder(false);

		view = new ListView<BusiObject>() {
			@Override
			protected BusiObject prepareData(BusiObject model) {
				return model;
			}

		};

		view.setTemplate(getTemplate());
		view.setStore(createStore());
		view.setHeight(500);
		view.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);  
		view.setItemSelector("div.thumb-wrap");
		view.getSelectionModel().addListener(Events.SelectionChange,
			new Listener<SelectionChangedEvent<BusiObject>>() {
				public void handleEvent(SelectionChangedEvent<BusiObject> be) {
					if(store.indexOf(view.getSelectionModel().getSelectedItem())>=0)
						store.gotorow(store.indexOf(view.getSelectionModel().getSelectedItem()));
				}
			});
		panel.add(view);
		return panel;
	}
	
	ContentPanel CreateBcodeView() {
		final ContentPanel panel = new ContentPanel();
		panel.setHeaderVisible(false);
		panel.setFrame(true);
		panel.setId("images-view");
		panel.setHeight(200);
		panel.setBodyBorder(false);

		bcodeview = new ListView<BusiObject>() {
			@Override
			protected BusiObject prepareData(BusiObject model) {
				return model;
			}
		};

		bcodeview.setTemplate(getBcodeTemplate());
		bcodeview.setStore(gethr_hostel_bcodeStore());
		bcodeview.setHeight(185);
		bcodeview.setItemSelector("div.thumb-wrap");
		bcodeview.getSelectionModel().addListener(Events.SelectionChange,
				new Listener<SelectionChangedEvent<BusiObject>>() {
					public void handleEvent(SelectionChangedEvent<BusiObject> be) {
					}
				});

		panel.add(bcodeview);
		return panel;
	}
	BaseComboBoxForm C_num;
	TextField<String> C_num2;
	TextField<String> C_num3;
	TextField<String> C_num4;
	BaseComboBoxX C_num5;
	BaseComboBoxX C_num6;

	BaseFormPanel createForm() {
		
		BaseFormPanel form = new BaseFormPanel(getStore(),false);
		TableLayout tl = new TableLayout(2);

		TableData td = new TableData();
		td.setRowspan(1);
		td.setHorizontalAlign(HorizontalAlignment.LEFT);
		td.setVerticalAlign(VerticalAlignment.TOP);
		td.setPadding(2);
		form.setLayout(tl);
		form.setHeaderVisible(false);

		form.add(new Label("衣柜编号:"),td);
		C_num2  = new TextField<String>(); 
		C_num2.setName("code");
		C_num2.setEnabled(false);
		C_num2.setAllowBlank(false);
		form.add(C_num2,td);
		form.add(new Label("衣柜名称:"),td);
		C_num3  = new TextField<String>(); 
		C_num3.setName("name");
		form.add(C_num3,td);

		form.add(new Label("衣柜性质:"),td);
		C_num5 = new BaseComboBoxX("name", "dictionary","where type='hr_sex'");
		C_num5.setName("sex");
		form.add(C_num5,td);
		form.add(new Label("衣柜状态:"),td);
		C_num6 = new BaseComboBoxX("name", "dictionary","where type='hr_ws'");
		C_num6.setName("status");
		form.add(C_num6,td);
		form.add(new Label("备注:"),td);
		C_num4  = new TextField<String>(); 
		C_num4.setName("mark");
		form.add(C_num4,td);
		form.inited(); 
		 
		C_num2.addListener(Events.Change, getListener());
		C_num3.addListener(Events.Change, getListener());
		C_num4.addListener(Events.Change, getListener());
		return form;
	};

	int sync = 0;
	Listener<BaseEvent> defaultlistener;
	private StringBuilder where = new StringBuilder();

	Listener<BaseEvent> getListener() {
		if (defaultlistener != null) {
			return defaultlistener;
		}

		defaultlistener = new Listener<BaseEvent>() {
			public void handleEvent(BaseEvent be) {
				sync++;
				try {
					if (sync == 1) {
						if (be.getType() == Events.Select) {
							where.delete(0, where.length());
							
							if (be.getSource().equals(addhoster)) {//添加衣柜
								createDialog().show();	
							}else if (be.getSource().equals(delhoster)) {//删除衣柜
								final String code = store.getAt(store.getCurcowindex()).get("code");
								MessageBox.confirm("提示", "你确定删除编号为’" + code + "‘的衣柜吗，确定请点‘是’，如果是误操作请点‘否’，谢谢", new Listener<MessageBoxEvent>() {
									public void handleEvent(MessageBoxEvent be) {
										if (be.getButtonClicked().getText().equals(
												GXT.MESSAGES.messageBox_yes())) {
											if(store.getCurcowindex()>0){
												String sql = "delete from hr_wardrode_bcode where upcode='"+code+"'";
												commandSql(sql);
												String sql2 = "update bcode_job set lockersno=null where lockersno='"+code+"'";
												commandSql(sql2);
												store.remove(store.getAt(store.getCurcowindex()));
												store.trySave();
											}
										}
									}
								});
							}
							else if (be.getSource().equals(btnAddBcode)) {//添加人员
								
								if(store.getCurcowindex()<0){
									MessageBox.alert("错误", "请先选择衣柜", null);
									return;
								}else if(hr_wardrode_bcodestore.getCount()>0){
									MessageBox.alert("错误", "所选择衣柜已被占用，请先删除人员再添加人员，谢谢",null);
									return;
								}else{
									SelectItemDialog s= new SelectItemDialog(){
										 protected void onOK()
										 {
											 final BusiObject bo =this.getGrid().getSelectionModel().getSelectedItem();
											 if(bo!=null){
												 String sql2 = "select case when a.sex=b.sex then 1 else 0 end as result " +
													"from(select sex from hr_wardrobe where code='"+store.getValue("code")+"')as a," +
															"(select sex from bcode where bcode='"+bo.get("bcode")+"') as b";
											final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT.create(com.base.myproject.client.tools.GreetingService.class);
											greetingService2.getDataSet(sql2, new AsyncCallback<DataSet>(){
												@Override
												public void onFailure(Throwable caught) {	
												}
												@Override
												 public void onSuccess(DataSet result) {
													if(result.getRowCount() > 0){
														String res = result.getValue(0, "result");
														if(Integer.parseInt(res) != 1){
															MessageBox.alert("错误", "员工性别与衣柜性质不一致", null);
														}else{
															BusiObject bcode_bo = new BusiObject();
															bcode_bo.set("bcode",bo.get("bcode"));
															bcode_bo.set("bname", bo.get("bname"));
															bcode_bo.set("upcode", store.getValue("code"));
															hr_wardrode_bcodestore.add(bcode_bo);
															hr_wardrode_bcodestore.trySave();
															updateward(store.getValue("code").toString());
															String sql = "update bcode_job set lockersno='"+store.getValue("code")+"' where bcode='"+bo.get("bcode")+"'";
															commandSql(sql);
															hr_wardrode_bcodestore.reload();
														}
													}
												}
											});	   			
											}
											 this.close();
										 }
										 
									 };
									 
									 s.setColumndisplayname(new String[]{"编码","名称","性别"});
									 s.setColumnname(new String[]{"bcode","bname","sex"});
									 CommandSyncGetModelDatas csgmd2 = new CommandSyncGetModelDatas();
									 csgmd2.setSqlname("hr_wardrodebcode");
									 s.setCsgmd2(csgmd2);
									 s.show();
								}
							}
							else if (be.getSource().equals(show_break)) {//已损坏衣柜
								store.getStoreinfo().setSql("select icode,code,name,sex,status,mark,'images/b2cimages/wardrode.gif' as" +
										" imagepath ,(select count(*) from hr_wardrode_bcode" +
										" where hr_wardrobe.code=hr_wardrode_bcode.upcode )" +
										" as usedcount  from hr_wardrobe where status = '损坏' ");
								where.append(" and status = '损坏'");
								store.reload();
							}else if(be.getSource().equals(seach)){//查询
								String code=seach_code.getRawValue();
								String name=seach_text.getRawValue();
								if(!code.equals("")){
									where.append(" and code='"+code+"'");
								}
								if(!name.equals("")){
									where.append(" and name='"+name+"'");
								}
								store.getStoreinfo().setSql("select icode,code,name,mark,'images/b2cimages/wardrode.gif' " +
										"as imagepath,(select count(*) from hr_wardrode_bcode" +
										" where hr_wardrobe.code=hr_wardrode_bcode.upcode )" +
										" as usedcount  from hr_wardrobe where 1=1 "+where);
								store.reload();
								
							}else if(be.getSource().equals(show_empty)){//显示空衣柜
								store.getStoreinfo().setSql("select icode,code,name,mark,'images/b2cimages/wardrode.gif' as" +
										" imagepath ,(select count(*) from hr_wardrode_bcode" +
										" where hr_wardrobe.code=hr_wardrode_bcode.upcode )" +
										" as usedcount  from hr_wardrobe where usedcount!=1 ");
								where.append(" and usedcount!=1");
								store.reload();
							}else if(be.getSource().equals(delbcode)){//删除人员
								if(store.getCurcowindex()<0){
									MessageBox.alert("错误", "请先选择衣柜", null);
									return;
								}
								final String code = store.getAt(store.getCurcowindex()).get("code");
								MessageBox.confirm("提示", "你确定删除编号为’" + code + "‘的衣柜的人员吗，确定请点‘是’，如果是误操作请点‘否’，谢谢", new Listener<MessageBoxEvent>() {
									public void handleEvent(MessageBoxEvent be) {
										if (be.getButtonClicked().getText().equals(
												GXT.MESSAGES.messageBox_yes())) {
											String sql = "delete from hr_wardrode_bcode where upcode='"+store.getValue("code")+"'";
											String sql2 = "update bcode_job set lockersno=null where lockersno='"+store.getValue("code")+"'";
											commandSql(sql);
											commandSql(sql2);
											store.reload();
											hr_wardrode_bcodestore.reload();
										}
									}
								});
							}
						} else if (be.getType() == Events.Change) {
							if (be.getSource().equals(C_num2)||be.getSource().equals(C_num3)||be.getSource().equals(C_num4)) {
								view.refresh();
							}
						}
					}
				} finally {
					sync--;
				}
			}

		};
		return defaultlistener;
	}
	
	ArrayList<BaseStore> refresh_list = new ArrayList<BaseStore>() ;
	void updateward(String code){	
		String sql="  update hr_wardrobe set usedcount=1 where code='"+code+"'";	//1 表示这个柜子已经被使用
		CommandSyncsql csql = new CommandSyncsql();	
			csql.getV().add(sql);
			if(csql.getV().size()>0){
				 GreetingServiceAsync greetingService = GWT
					.create(GreetingService.class);
				 CommandSyncContainer list = new CommandSyncContainer();
				 list.add(csql);
				 greetingService
					.SendCommandSync(
							list,
							new AsyncCallback<CommandSyncReturnObject>() {
								@Override
								public void onFailure(
										Throwable caught) {
									MessageBox.alert("错误",
											"网络连接失败", null);	
								}
								@Override
								public void onSuccess(
										CommandSyncReturnObject result) {
									if (result.isB()) {
										DeferredCommand.addCommand(new Command() {
										      public void execute() {	
										    	//   Info.display("提示", "操作成功!");									    	
										      }
										    });
									}
									else{
										MessageBox.alert("错误",
												"错误，错误代码"+result.getMessage(), null);
										
									}
								}
							});
			}	 
	}
	Dialog createDialog()
	{
		final Dialog d = new Dialog();
		final FormPanel fp = new FormPanel();
		final TextField<String> code = new TextField<String>();
		final BaseComboBoxX sex = new BaseComboBoxX("name", "dictionary","where type='hr_sex'");
		
		code.setAllowBlank(false);
		
	
		code.setFieldLabel("衣柜号");
		sex.setFieldLabel("衣柜性质");
		
		fp.add(code);
		fp.add(sex);
	
		d.add(fp);
		d.setButtons(Dialog.OKCANCEL);
		d.getButtonById(Dialog.OK).addSelectionListener(new SelectionListener<ButtonEvent>(){

			@Override
			public void componentSelected(ButtonEvent ce) {
				final String codeNumber = code.getValue();
				
				if(fp.isValid() && !codeNumber.matches("\\s*")) {
					String sql2 = "select * from hr_wardrobe where code = '" + codeNumber + "'";
					final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT
							.create(com.base.myproject.client.tools.GreetingService.class);
					greetingService2.getDataSet(sql2,
							new AsyncCallback<DataSet>() {
								@Override
								public void onFailure(Throwable caught) {
								}

								@Override
								public void onSuccess(DataSet result) {
									if (result.getRowCount() > 0) {
										code.setValue("");
										MessageBox.alert("提示", "你输入的衣柜号已经存在，请重新输入，谢谢", null);
									} else {
										BusiObject bo = new BusiObject();
										bo.set("code",	codeNumber);
										bo.set("sex", sex.getValue());
										bo.set("usedcount", 0);
										getStore().add(bo);
										d.hide();
										view.getSelectionModel().select(store.getAt(store.getCurcowindex()), false);
										//添加钥匙
										CommandSyncContainer list = new CommandSyncContainer();
										CommandSyncExeSql csgmd = new CommandSyncExeSql();
										csgmd.setSqlname("hr_wardrode_addkey");
										csgmd.putmacro("CODE", "衣柜钥匙"+code.getValue());
										csgmd.putmacro("NAME", "衣柜钥匙"+code.getValue());
										
										list.add(csgmd);
										
										final com.base.myproject.client.tools.GreetingServiceAsync greetingService = GWT
												.create(com.base.myproject.client.tools.GreetingService.class);
										greetingService
												.SendCommandSync(
														list,
														new AsyncCallback<CommandSyncReturnObject>() {

															@Override
															public void onFailure(
																	Throwable caught) {
																MessageBox.alert("错误",
																		"网络连接失败", null);

															}

															@Override
															public void onSuccess(
																	CommandSyncReturnObject result) {
																if (result.isB()) {
																	Info.display("", "成功");
																} else {
																	MessageBox
																			.alert(
																					"错误",
																					""
																							+ result
																									.getMessage(),
																					null);
																	d.el().blink(FxConfig.NONE);  
																}

															}

														});
									}
								}
							});
				} else {
					MessageBox.alert("提示", "请输入完整的衣柜的信息，谢谢", null);
				}
				
			}
			
		});
		d.getButtonById(Dialog.CANCEL).addSelectionListener(new SelectionListener<ButtonEvent>(){

			@Override
			public void componentSelected(ButtonEvent ce) {
				d.setVisible(false);
				
			}
			
		});
		
		fp.setAutoHeight(true);
		fp.setAutoWidth(true);
		
		fp.setHeading("添加");
		d.setSize(366, 165);
		return d;
		
		
	}
	private native String getBcodeTemplate() /*-{
	return ['<tpl  for=".">', 
	'<div class="thumb-wrap" id="{bcode}" style="border: 1px solid white;float:left;text-align:center;">', 
	'<div class="thumb"><img style="width:150px;height:150px;border:5px double #eee;margin: 3px 2px 2px 3px;" src="{imagepath}" title="{bcode}"></div>', 
	'<span class="x-editable" style="float:left" >{bcode}:{bname}</span></div>', 
	'</tpl>',
	'<div class="x-clear"></div>'].join("");
	}-*/;
	private native String getTemplate() /*-{
		return ['<tpl  for=".">', 
		'<div class="thumb-wrap" id="name"',
		'<tpl if="usedcount ==1">',
		' style="border: 1px solid red;float:left;"', 
		'</tpl>',
		'<tpl if="usedcount ==0">',
		' style="border: 1px solid white;float:left;"',
		'</tpl>',
		'>',
		
		'<div class="thumb" ><img style="width:70px;height:80px;border:5px double #eee;margin: 3px 2px 2px 3px" src="{imagepath}" title="{name}"></div>', 
		'<span class="x-editable" style="float:left" >&nbsp;&nbsp;&nbsp;&nbsp; {code}</span></div>', 
		'</tpl>',
		'<div class="x-clear"></div>'].join("");
	}-*/;
	
	private boolean commandSql(String sql) {
		CommandSyncsql csql = new CommandSyncsql();// 执行sql命令
		String delsql = sql;
		csql.getV().add(delsql);
		if (csql.getV().size() <= 0) {
			return false;
		} else {
			CommandSyncContainer list = new CommandSyncContainer();// 可以添加的命令
			list.add(csql);

			GreetingServiceAsync greetingService = GWT
					.create(GreetingService.class);
			greetingService.SendCommandSync(list,
					new AsyncCallback<CommandSyncReturnObject>() {
						@Override
						public void onFailure(Throwable caught) {
							MessageBox.alert("错误", "网络连接失败", null);
						}

						@Override
						public void onSuccess(CommandSyncReturnObject result) {
							if (result.isB()) {
							//	Info.display("提示信息", "添加成功");
							} else {
								MessageBox.alert("错误", "错误，错误代码"
										+ result.getMessage(), null);
							}
						}
					});
		}
		return true;
	}
}
